<template>
  <div class="win">
    <div class="express_box">
      <div
        class="item"
        @click="currentChoose(index,item)"
        v-for="(item, index) in expressData"
        :key="index"
      >
        <p>{{item.name}}</p>
        <div>
          <img v-if="current==index" :src="bjurl+'check_green_logo.png'" />
          <img v-else :src="bjurl+'check_grey_logo.png'" />
        </div>
      </div>
    </div>
    <!-- <button
      :class="current=='undefined'?'grey':''"
      @click="hr_orderConfirm"
    >确定</button>-->
    <button :class="current=='undefined'?'grey':''" @click="backPage(current)">确定</button>
    <i-toast id="toast" />
  </div>
</template>

<script>
export default {
  data() {
    return {
      bjurl: "",
      expressData: [],
      current: 0 //默认选择快递
    };
  },
  methods: {
    // 请求接口物流信息
    getLogistic() {
      this.$ajax("/home/order/getlogistic", "post", {})
        .then(res => {
          
          if (res.status) {
            this.expressData = res.data;
          } else {
          }
        })
        .catch(err => {});
    },
    //切换物流信息
    currentChoose(index) {
      if (this.current == index) return;
      else this.current = index;
    },
    // 退回到订单确认也
    backPage(current) {
      if (this.current == "undefined") {
        this.$toast({
          content: "请选择物流~"
        });
      } else {
        this.$ajax("/home/order/chooseLogistic", "post", {
          logistic_id: this.expressData[current].logistic_id
        })
          .then(res => {
            if (res.status) {
              this.$bus.$emit("wuliuInfo", {
                express: this.expressData[current].name,
                logistic_id: this.expressData[current].logistic_id,
                current: this.current
              });
              wx.navigateBack({
                delta: 1
              });
            } else {
            }
          })
          .catch(err => {});
      }
    }
  },
  onLoad(e) {
    Object.assign(this.$data, this.$options.data());
    this.getLogistic();
    this.bjurl = this.$bjurl;
    this.expressData = expressData;
    this.current = e.current;
  }
};
let expressData = ["顺丰快递", "中通快递", "圆通快递", "韵达快递", "申通快递"];
</script>

<style lang="scss" scoped>
.win {
  .express_box {
    .item {
      margin-top: 10rpx;
      box-shadow: -1rpx 7rpx 9rpx 0rpx rgba(169, 169, 169, 0.14);
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 60rpx 0 30rpx;
      height: 106rpx;
      font-size: 32rpx;
      background-color: #ffffff;
      color: #4d4d4d;
      img {
        width: 34rpx;
        height: 34rpx;
      }
    }
  }
  button {
    width: 692rpx;
    height: 92rpx;
    line-height: 92rpx;
    border-radius: 46rpx;
    background: linear-gradient(
      0deg,
      rgba(11, 208, 94, 1),
      rgba(11, 208, 173, 1)
    );
    color: #ffffff;
    font-size: 40rpx;
    letter-spacing: 3rpx;
    margin: 180rpx auto 0;
  }
  .grey {
    background: #cccccc;
  }
}
</style>
